<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>班级管理</title>
<script src="${ctxStatic}/front/js/myValidate.js"></script>
<script src="${ctxStatic}/front/js/messages_zh.min.js"></script>
<meta name="decorator" content="default" />
<script type="text/javascript">
	$(document).ready(
			function() {
				$("#inputForm")
						.validate(
								{
									rules : {
										grade : {
											digits : true,
											min : 1
										},
										classes : {
											digits : true,
											min : 0
										},
										classroomId: {
											required : true
										},
										category : {
											required : true
										}
									},
									messages : {
										grade : {
											required : "请选择",
											digits : "请填写正整数",
											min : "必须大于0"
										},
										classes : {
											digits : "请填写正整数",
											min : "必须大于0"
										},
										classroomId: {
											required : "请选择"
										},
										category : {
											required : "请选择"
										}
									},
									submitHandler : function(form) {
										loading('正在提交，请稍等...');
										form.submit();
									},
									errorContainer : "#messageBox",
									errorPlacement : function(error, element) {
										$("#messageBox").text("输入有误，请先更正。");
										if (element.is(":checkbox")
												|| element.is(":radio")
												|| element.parent().is(
														".input-append")) {
											error.appendTo(element.parent()
													.parent());
										} else {
											error.insertAfter(element);
										}
									}
								});
				$("#category").change(function(){
			    	 var category=$("#category").val();
				     $.ajax({
				         type: "POST",
				         url: "${ctx}/ajax/get/gradeDict.do",
				         data: {"category":category},
				         dataType: 'json',
				         success: function(data) {
				               $("#grade").empty();
				               $("#grade").append("<option selected=\"selected\" value=\"\">请选择</option>" );
				               $.each(data, function(index,item){
				             		$("#grade").append('<option value='+item.value+'>'+item.label+'</option>');
				              }); 
				              /*  $("#s2id_grade").find("span[class='select2-chosen']").html("请选择"); */
				             }
				  		});
				     });
				//类别+年级级联到年级
				$("#grade").change(function(){
			        var studentId=$("#studentId").val();
			        var grade=$("#grade").val();
			     $.ajax({
			         type: "POST",
			         url: "${ctx}/ajax/get/class.do",
			         data: {"studentId":studentId,"grade":grade},
			         dataType: 'json',
			         success: function(data) {
			               $("#classes").empty();
			               $("#classes").append("<option selected=\"selected\" value=\"0\">请选择</option>" );
			               $.each(data, function(index,item){
			             		$("#classes").append('<option value='+item.id+'>'+item.classes+'</option>');
			              }); 
			               $("#s2id_classes").find("span[class='select2-chosen']").html("请选择");
			             }
			  		});
			     });
			});
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/dd/ddClasses/">班级列表</a></li>
		<li class="active"><a
			href="${ctx}/dd/ddClasses/form?id=${ddClasses.id}">班级<shiro:hasPermission
					name="dd:ddClasses:edit">${not empty ddClasses.id?'修改':'添加'}</shiro:hasPermission>
				<shiro:lacksPermission name="dd:ddClasses:edit">查看</shiro:lacksPermission></a></li>
	</ul>
	<br />
	<form:form id="inputForm" modelAttribute="ddClasses"
		action="${ctx}/dd/ddClasses/save" method="post"
		class="form-horizontal">
		<form:hidden path="id" />
		<sys:message content="${message}" />
		<div class="control-group">
			<label class="control-label"> <b
				style="color: red; font-size: large">*</b>教室：
			</label>
			<div class="controls">
				<%-- <form:input path="classroomId" htmlEscape="false" maxlength="32" class="input-xlarge " required="required"/> --%>
				<form:select path="classroomId"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getClassRoomNameList(schoolId)}"
						itemLabel="name" itemValue="id" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b
				style="color: red; font-size: large">*</b>类别：
			</label>
			<div class="controls">
				<form:select path="category"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getDictList('category')}"
						itemLabel="label" itemValue="value" htmlEscape="false" class="" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b
				style="color: red; font-size: large">*</b>年级：
			</label>
			<div class="controls">
						<form:select path="grade"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getDictList('grade')}"
						itemLabel="label" itemValue="value" htmlEscape="false" class="" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b
				style="color: red; font-size: large">*</b>班级：
			</label>
			<div class="controls">
				<form:input path="classes" htmlEscape="false" maxlength="20"
					class="input-xlarge " required="required" />
			</div>
		</div>
		
		<div class="form-actions">
			<shiro:hasPermission name="dd:ddClasses:edit">
				<input id="btnSubmit" class="btn btn-primary" type="submit"
					value="保 存" />&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回"
				onclick="history.go(-1)" />
		</div>
	</form:form>
</body>
</html>